<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">
		<link href="../css/mui.listpicker.css" rel="stylesheet" />
		<link href="../css/mui.poppicker.css" rel="stylesheet" />
		<!--App自定义的css-->
		<style>
			#content {
				border-top: 0;
				border-left: 0;
				border-right: 0;
				border-radius: 0;
			}
			.mui-pull-right {
				line-height: 45px;
			}
			.ui-alert {
				text-align: center;
				padding: 20px 10px;
				font-size: 16px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">创建话题</h1>
			<a href="javascript:save();" class="mui-pull-right">提交</a>
		</header>
		<div class="mui-content">
			<div class="mui-input-group">
				<div class="mui-input-row">
					<input type="hidden" id="sid" value="1">
					<input type="text" id="showSectionPicker" disabled="disabled" value="问答">
				</div>
				<div class="mui-input-row">
					<input type="text" id="title" value="" placeholder="标题10字以上">
				</div>
			</div>
			<div class="mui-input-row">
				<textarea placeholder="内容" rows="5" id="content"></textarea>
			</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script src="../js/mui.listpicker.js"></script>
		<script src="../js/mui.poppicker.js"></script>
		<script src="../js/common.js"></script>
		<script type="text/javascript" charset="utf-8">
			mui.init();
			mui.plusReady(function() {
				
			});
			
			var sectionPicker = new mui.PopPicker();
			sectionPicker.setData([{
				value: '8',
				text: '灌水'
			}, {
				value: '7',
				text: '资讯'
			}, {
				value: '1',
				text: '问答'
			}, {
				value: '2',
				text: '博客'
			}]);
			var showSectionPickerButton = document.getElementById('showSectionPicker');
			showSectionPickerButton.addEventListener('tap', function(event) {
				sectionPicker.show(function(items) {
					document.getElementById("sid").value = items[0].text;
					showSectionPickerButton.value = items[0].text;
				});
			}, false);
		
			function save() {
				var sid = document.getElementById("sid");
				var title = document.getElementById("title");
				var content = document.getElementById("content");
				if(trim(title.value).length < 10) {
					mui.toast("标题10字以上");
				} else if(trim(content.value).length == 0) {
					mui.toast("请输入内容");
				} else {
					mui.ajax({
						type: "post",
						url: _baseUrl + "/api/topic/create",
						data: {
							token: plus.storage.getItem(_user_token),
							title: title.value,
							content: content.value,
							sid: sid.value
						},
						async: true,
						dataType: "json",
						success: function(data) {
							if(data.code == 200) {
								title.value = "";
								content.value = "";
								topic_detail(data.detail.id);
//								plus.webview.getWebviewById('create.html').close();
							} else {
								mui.toast(data.description);
							}
						}
					});
				}
			}
		</script>
	</body>

</html>